<template>
  <el-dialog
      :close-on-click-modal="false"
      destroy-on-close
      :show-close="false"
      width="30%"
      v-model="CHUSHAIDATA"
      title="候选人初筛"
  >
    <!-- <el-form
        ref="ruleFormRef"
        label-width="100px"
        :model="formData"
        :rules="formRules"
        size="small"
        :inline="false"
    > -->
      <!-- <el-form-item label="主题" prop="title">
        <el-input
            v-model="formData.title"
            placeholder="请输入主题"
            maxlength="32"
            size="small"
        />
      </el-form-item>
      <el-form-item label="候选人" prop="candidateId">
        <el-select
            v-model="formData.candidateId"
            placeholder="请选择候选人"
            style="width: 100%"
            size="small"
            filterable
        >
          <el-option
              v-for="item in candidateList"
              :key="item.id"
              :value="item.id"
              :label="item.name"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="筛选人" prop="executorIds">
        <el-select
            v-model="executorId"
            placeholder="请选择筛选人"
            @change="executorSelected"
            size="small"
            filterable
        >
          <el-option
              v-for="item in relatorList"
              :key="item.userId"
              :value="item.userId"
              :label="item.nickname"
          />
        </el-select>
      </el-form-item> -->
      <!-- {{ formData.actionStartTime }} -->
      <!-- <el-form-item label="筛选时间">
        <div style="max-width: 400px">
          <el-date-picker
              v-if="dateType"
              v-model="dateTime"
              style="width: 100%"
              type="datetimerange"
              range-separator="至"
              start-placeholder="行动开始时间"
              end-placeholder="行动结束时间"
              value-format="YYYY-MM-DD HH:mm:ss"
              @change="selectTime"
          />
          <el-date-picker
              v-else
              v-model="formData.actionStartTime"
              type="datetime"
              style="width: 100%"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择筛选时间"
          />
        </div>
        <el-button style="margin-left: 10px" plain :icon="Refresh" @click="dateType = !dateType"/>
      </el-form-item>
      <el-form-item label="优先度">
        <el-radio-group v-model="formData.priority">
          <el-radio :label="0" size="small">普通</el-radio>
          <el-radio :label="1" size="small">高</el-radio>
        </el-radio-group>
      </el-form-item> -->
      <!--    <el-form-item label="通知时间" prop="remindState">-->
      <!--      <el-radio-group v-model="formData.remindState">-->
      <!--        <el-radio v-for="item in remindTimes" :key="item.value" :label="item.value" size="small">{{ item.label }}</el-radio>-->
      <!--      </el-radio-group>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="通知方式" prop="remindType">-->
      <!--      <el-checkbox-group v-model="formData.remindType" size="small">-->
      <!--        <el-checkbox label="1">应用、公众号通知</el-checkbox>-->
      <!--        <el-checkbox label="2">短信通知</el-checkbox>-->
      <!--      </el-checkbox-group>-->
      <!--    </el-form-item>-->
    <!-- </el-form> -->
    <initial-sift-form ref="form" :selectTime="thisTime"></initial-sift-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button size="large" @click="close()">取消</el-button>
        <el-button @click="submit()" type="primary" size="large">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
// 初筛 OA_INITIAL_SIFT
import {onMounted, reactive, toRefs, ref} from 'vue'
// import {getListByType} from '/@/api/oa/candidate'
// import {getEnterpriseUsers} from '/@/api/sys/user'
// import {getRemindTimes} from '/@/api/matter'
// import {homeApi} from '/@/api/home/index'
// import {Refresh} from '@element-plus/icons-vue'

import InitialSiftForm from '/@/views/matter/components/InitialSiftForm.vue'

// const homeCalendar = homeApi()
export default {
  name: 'InitialSift',
  props: {
    CHUSHAIDATA: {
      type: Boolean,
      default: true
    },
    idw: {
      type: String,
      default: ''
    },
    thisTime: {
      type: String,
      default: ''
    }
  },
  emits: ['ChiShaiormClose'],
  components: {
    InitialSiftForm
  },
  setup(props, context) {
    // const {idw, thisTime} = toRefs(props)
    const form = ref()
    const state = reactive({
      // formData: {
      //   // id:idw.value,
      //   candidateId: null, // 候选人id
      //   title: '候选人初筛', // 事项主题
      //   content: '',      // 事项描述
      //   state: 0,           // 状态 -1草稿 0未开始 1进行中 2已完成 3已退回  4已取消 5已撤回
      //   priority: 0, // 优先级 0普通 1重要
      //   executorIds: [], // 执行人id 初筛的先做成单选, 如果要多选再改
      //   actionStartTime: null,   // 事项开始时间
      //   actionEndTime: null,
      //   remindState: 'NONE', // 提醒时间, 根据枚举类MatterRemindTimeEnum
      //   remindType: null     // 提醒方式, 多选
      // },
      // dateType: false,  // 行动时间范围/单体切换
      // dateTime: [],
      // executorId: null, // 每次选择执行人都覆盖原来的 formData.executorIds
      // relatorList: [], // 关联人数据列表
      // candidateList: [], // 候选人数据列表
      // remindTimes: [] // 提醒时间列表
    })
    // const ruleFormRef = ref({})
    // const defaultTime = ref('')
    // const formRules = reactive({
    //   candidateId: {required: true, message: '请选择候选人', trigger: 'change'},
    //   title: {required: true, message: '请输入事项主题', trigger: 'blur'},
    //   executorIds: {required: true, message: '请选择执行人', trigger: 'change'}
    // })
    // const dealWithTime = () => {

    //   const data = new Date()
    //   let formatDateTime
    //   let Y = data.getFullYear()
    //   let M = data.getMonth() + 1
    //   let D = data.getDate()
    //   let H = data.getHours()
    //   let Min = data.getMinutes()
    //   let S = data.getSeconds()
    //   let W = data.getDay()
    //   M = M < 10 ? '0' + M : M
    //   D = D < 10 ? '0' + D : D
    //   H = H < 10 ? '0' + H : H
    //   Min = Min < 10 ? '0' + Min : Min
    //   S = S < 10 ? '0' + S : S
    //   // this.nowDate = Y + "年" + M + "月" + D + "日 ";
    //   // this.nowWeek = "周" + W ;
    //   // this.nowTime = H + ":" + Min + ":" + S;
    //   return formatDateTime = thisTime.value + ' ' + H + ':' + Min + ':' + S
    // }
    // const getCandidateData = async () => {
    //   try {
    //     const res = await getListByType('0') // 获取待初筛的
    //     state.candidateList = res.data
    //   } catch (e) {
    //     console.log(e)
    //   }
    // }
    let close = () => {
      // if (data) {
      //   context.emit('ChiShaiormClose', data)
      // } else {
      //   context.emit('ChiShaiormClose')
      // }

      // resetForm(formEl)
      form.value.reset()
    }
    // const getRemindData = async() => {
    //   try {
    //     const res = await getRemindTimes()
    //     state.remindTimes = res.data
    //   } catch (e) {
    //     console.log(e)
    //   }
    // }
    let submit = () => {
      form.value.submit()
      // state.formData.occurDate = format(state.occurDate, 'yyyy-MM-dd HH:mm')
      // state.formData.settlementDate = format(state.settlementDate, 'yyyy-MM-dd HH:mm')
      // state.form.id = idw.value;
      // if (!formEl) return
      // await formEl.validate((valid, fields) => {
      //   if (valid) {
      //     // state.formData.executorIds = JSON.stringify(state.formData.executorIds)
      //     homeCalendar.addInitialSift(state.formData).then((res) => {
      //       if (res.code === 0) {
      //         resetForm(formEl)
      //         close(formEl, res.data)
      //       }
      //     })
      //   } else {
      //     console.log('error submit!', fields)
      //   }
      // })

      // console.log(state.formData);
      // state.form.id = idw.value
      // homeCalendar
      //   .modifyMatter(state.formData)
      //   .then((res) => {
      //       if(res.code===1){

      //       }
      //   });
    }
    // const selectTime = (val) => {
    //   if (val && val.length === 2) {
    //     state.formData.actionStartTime = val[0]
    //     state.formData.actionEndTime = val[1]
    //   } else {
    //     state.formData.actionStartTime = state.formData.actionEndTime = null
    //   }
    // }
    // const resetForm = (formEl) => {
    //   if (!formEl) return
    //   formEl.resetFields()
    // }
    // const executorSelected = (val) => {
    //   state.formData.executorIds = [val]
    // }
    onMounted(() => {
      // getCandidateData()
      // getEnterpriseUsers().then(res => state.relatorList = res.data)
      // getRemindData()
      // const time = dealWithTime()
      // state.formData.actionStartTime = time
      // defaultTime.value = time

    })
    return {
      ...toRefs(state),
      // getCandidateData,
      // executorSelected,
      submit,
      close,
      form
      // formRules,
      // ruleFormRef,
      // resetForm,
      // dealWithTime,
      // defaultTime,
      // Refresh,
      // selectTime
      // getRemindData
    }
  }
}
</script>

<style lang="scss" scoped></style>
